package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.infos.IntegralInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.JsonUtil;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.IntegralView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/10/11.
 */

public class IntegralP extends BasePresenter implements VolleyCallBack<JSONObject> {
    IntegralView integralView;

    public IntegralP(IntegralView integralView) {
        this.integralView = integralView;
    }

    @Override
    public void addData(String url) {
        integralView.showdialog();
        sendJsonObjectUrl(url, this);
    }

    @Override
    public void onResponse(JSONObject jsonObject) {
//      List<IntegralInfo> integralInfos= myJson.getIndentSomething(jsonObject);

        try {
            List<IntegralInfo> integralInfos = JsonUtil.getListFromString(jsonObject.getString("res"), IntegralInfo.class);
            integralView.sendList(integralInfos);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        integralView.dissmissdialog();
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
        integralView.dissmissdialog();
    }
}
